import 'package:flutter/material.dart';

final List<String> images = [
  'http://g.hiphotos.baidu.com/image/pic/item/86d6277f9e2f07084eacbbebe724b899a801f2b4.jpg',
  'http://e.hiphotos.baidu.com/image/pic/item/cf1b9d16fdfaaf51af659339815494eef11f7ab5.jpg',
  'http://b.hiphotos.baidu.com/image/pic/item/838ba61ea8d3fd1f6888e8bc3b4e251f94ca5fb6.jpg',
  'http://g.hiphotos.baidu.com/image/pic/item/4d086e061d950a7b949dfa7e00d162d9f3d3c9e4.jpg',
];
int _currentPageIndex = 0;
var _pageController = new PageController(initialPage: 0);
final List<String> descriptions = [
  '不摇碧莲，干翻苍穹',
  '周五快到了，准备追更新',
  '社会我宝姐，人美路子野',
  '社会我宝姐，人美路子野',
];

class MyAppa extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Gallery Demo',
      theme: ThemeData(primarySwatch: Colors.deepOrange),
      home: DisplayPage(),
    );
  }
}

class DisplayPage extends StatefulWidget {
  @override
  _DisplayPageState createState() => new _DisplayPageState();
}

class _DisplayPageState extends State<DisplayPage> {
 // bool _isAddGradient = false;

  @override
  Widget build(BuildContext context) {
   /* FloatingActionButton _floatingActionButton = FloatingActionButton(
      onPressed: () {
        _isAddGradient = !_isAddGradient;
        setState(() {
          _isAddGradient;
        });
      },
      tooltip: 'Switch Gradient Effect',

    );*/

    var decorationBox = DecoratedBox(
      decoration:   BoxDecoration(),
    );

    return Scaffold(
      appBar: new AppBar(
        title: new Text("图片"),
        centerTitle: true,
      ),

      body: Center(
        child: SizedBox.fromSize(
          size: Size.fromHeight(500.0),
          child: PageView.builder(
            controller: PageController(viewportFraction: 0.8),
            itemCount: images.length,
            itemBuilder: (BuildContext context, int index) {
              return Padding(
                padding: EdgeInsets.symmetric(
                  vertical: 16.0,
                  horizontal: 8.0,
                ),

                child: GestureDetector(
                  onTap: () {
                    Scaffold.of(context).showSnackBar(SnackBar(
                      backgroundColor: Colors.deepOrangeAccent,
                      duration: Duration(milliseconds: 800),
                      content: Center(
                        child: Text(
                          descriptions[index],
                          style: TextStyle(fontSize: 25.0),
                        ),
                      ),
                    ));
                  },
                  child: Material(
                    elevation: 5.0,
                    borderRadius: BorderRadius.circular(8.0),
                    child: Stack(
                      fit: StackFit.expand,
                      children: [
                        Image.network(
                          images[index],
                          fit: BoxFit.cover,
                        ),
                        decorationBox,
                      ],
                    ),
                  ),
                ),
              );
            },
          ),
        ),
      ),
      bottomNavigationBar: new BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
              icon: new Icon(Icons.category), title: new Text("首页")),
          BottomNavigationBarItem(
              icon: new Icon(Icons.message), title: new Text("我的")),
        ],
        currentIndex: _currentPageIndex,
        onTap: onTap,
      ),
    );
  }
}

void onTap(int index) {
  _pageController.animateToPage(index,
      duration: const  Duration(microseconds: 300), curve: Curves.ease);
}

void _pageChange(int index) {
  /* setState((){
    if(_currentPageIndex!=index)
      {
        _currentPageIndex=index;
      }
  });*/
}

//void main() => runApp(MyApp());
